package com.wuxinwudai.android.app;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

/**
 * ExFragmentPagerAdapter 类为 FragmentPagerAdapter 类的简单扩展类型
 * Created by Deep on 2016/5/25.
 */
public final class ExFragmentPagerAdapter extends FragmentPagerAdapter {
    private Class[] mFragments;//Fragment 类型列表;
    private Context mContext;//上下文对象

    /**
     * 构造函数，初始化 ExFragmentPagerAdapter 类的一个新实例
     * @param fm FragmentManager 对象
     * @param context 上下文对象
     * @param fragments Fragment 类型数组
     */
    public ExFragmentPagerAdapter(FragmentManager fm, Context context,@NonNull  Class[] fragments) {
        super(fm);
        mContext = context;
        mFragments = fragments;
    }

    @Override
    public Fragment getItem(int position) {
        return Fragment.instantiate(mContext,mFragments[position].getName());
    }

    @Override
    public int getCount() {
        return mFragments.length;
    }
}
